import { Message } from "element-ui";
import { HTTP_OK } from "./constants";

/**
 * 报告通用请求的错误
 * @param param0
 * @returns
 */
export function checkHttpError({ status, detail }: HttpResponse): boolean {
  if (status && status !== HTTP_OK) {
    Message.error(detail);
    return false;
  }
  return true;
}

/**
 * 请求的通用结构
 */
export type HttpResponse<T = any | string> = {
  status?: "ok" | "error";
  detail: T;
};
